/*
 * Copyright (C) 2024 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the 'License');
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an 'AS IS' BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef IMAGE_KNIFE_C_IMAGEKNIFE_DATA_NAPI_H
#define IMAGE_KNIFE_C_IMAGEKNIFE_DATA_NAPI_H

#include <unordered_map>
#include "node_api.h"
#include "request/imageknife_request_internal.h"
#include "imageknife_data_napi.h"
namespace ImageKnifePro {

// 图片加载的阶段
enum class LoadPhase {
    // 调度阶段
    DISPATCH,
    // 内存缓存阶段
    MEMORY_CACHE,
    // 文件缓存阶段
    FILE_CACHE,
    // 图片加载阶段
    LOAD_IMAGE_FETCH,
    // 解码阶段
    DECODE,
    // 降采样阶段
    DOWN_SAMPLE,
    // 图形变换阶段
    TRANSFORM
};

// ImageKnifeDataNapi 类声明
class ImageKnifeDataNapi {
public:
    // 将 imageData 所有属性逐个添加到 JS 对象
    static napi_value ConvertToJSObject(napi_env env, const ImageInfo &imageInfo);

    static uint64_t GetTimestamp();

    // 静态映射表，映射 LoadPhase 到字符串
    static std::unordered_map<LoadPhase, std::string> phaseToStringMap;

private:
    // 设置基本属性
    static void SetBasicProperties(napi_env env, napi_value result, const ImageInfo &data);

    // 设置 TimeInfo 属性
    static void SetTimeInfoProperties(napi_env env, napi_value result, const TimeInfo& timeInfo);

    // 设置 ErrorInfo 属性
    static void SetErrorInfoProperties(napi_env env, napi_value result, const ErrorInfo& errorInfo);
    
    static napi_value CreateImageInfo(napi_env env, int32_t width, int32_t height);
};

} // namespace ImageKnifePro

#endif // IMAGE_KNIFE_C_IMAGEKNIFE_DATA_NAPI_H
